package sys.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sys.core.ResponseResult;
import sys.core.annotation.LoginRequired;
import sys.core.annotation.RecordLog;
import sys.entity.PageData;
import sys.entity.StudentEntity;
import sys.entity.TbUserEntity;
import sys.service.StudentService;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/student")
@Api(tags = "学生管理")
@Slf4j
public class StudentController {


    @Autowired
    private StudentService studentService;


    /**
     * 查询
     *
     * @return
     */
    @ApiOperation(value = "查询")
    @LoginRequired
    @RecordLog
    @PostMapping(value = "/select")
    public List<StudentEntity> select(@RequestBody StudentEntity StudentEntity) {
        return studentService.select(StudentEntity);
    }

    /**
     * X
     * 模糊查询
     *
     * @returnW
     */
    @ApiOperation(value = "模糊查询")
    @LoginRequired
    @RecordLog
    @PostMapping(value = "/likeSelect")
    public PageData<StudentEntity> likeSelect(@RequestBody StudentEntity StudentEntity) {
        return studentService.likeSelect(StudentEntity);
    }


    /**
     * 添加
     *
     * @return
     */
    @ApiOperation(value = "添加")
    @LoginRequired
    @RecordLog
    @PostMapping(value = "/add")
    public void add(@RequestBody StudentEntity entity) {
        studentService.add(entity);
    }

    /**
     * 导出excel
     *
     * @return
     */
    @ApiOperation(value = "导出excel")
    @LoginRequired
    @RecordLog
    @GetMapping("/exportExcel")
    public void exportExcel(StudentEntity entity, HttpServletResponse response) {
        studentService.exportExcel(entity, response);
    }


    /*   */

    /**
     * 学生统计
     *
     * @return
     *//*
    @ApiOperation(value = "studentCount")
    *//*  @LoginRequired*//*
    @RecordLog
    @PostMapping(value = "/studentCount")
    public ResponseResult studentCount() {
        return studentService.studentCount();
    }*/
    @ApiOperation(value = "学生统计", notes = "学生统计")
    @PostMapping("/studentCount")
    public ResponseResult studentCount() {

        return studentService.stuCount();


    }

    @ApiOperation(value = "学生统计", notes = "学生统计")
    @PostMapping("/test")
    public void test(@RequestBody StudentEntity studentEntity) {

       log.info("studentEntity:{}",studentEntity);
       studentService.add(studentEntity);


    }



    @PostMapping("addStudent")
    @LoginRequired
    @RecordLog
    @ApiOperation(value = "新增学生",notes = "新增学生")
    public void addStudent(@RequestBody StudentEntity studentEntity){
        log.info("studentEntity:{}",studentEntity);
        studentService.add(studentEntity);

    }








}
